<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item to="/home">首页</el-breadcrumb-item>
      <el-breadcrumb-item>数据统计</el-breadcrumb-item>
      <el-breadcrumb-item>数据报表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
      <div id="main" style="width: 750px;height:400px;" ref="main"></div>
    </el-card>
  </div>
</template>

<script>
import * as echarts from 'echarts'
import _ from 'lodash'
export default {
  data() {
    return {
      options: {
        title: {
          text: '用户来源'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#E9EEF3'
            }
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            boundaryGap: false
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ]
      }
    }
  },
  async mounted() {
    this.getData()
    // this.test()
    // console.log('---------------')
    // this.test2()
    // this.testJs()
  },
  methods: {
    testJs() {
      // var data = { name: [1] }
      // console.log(data)
      // data.name.push(200)
      // console.log(data)

      var data = { name: { id: 100 } }
      console.log(data)
      data.name.id = 200
      console.log(data)

      /* var data = { name: '1' }
      console.log(data)
      data.name = '200'
      console.log(data) */
    },
    test2() {
      const obj = { name: ['lisi', 'zhangsan'] }
      console.log(obj)
      const data = { age: 18, name: 'wangwu' }
      Object.assign(obj, data)
      console.log(obj)
    },
    test() {
      console.log('fuction: test-----')
      const obj = { name: ['lisi', 'zhangsan'] }
      console.log(1, obj)
      const data = { age: 18, name: 'wangwu' }
      _.merge(obj, data)
      console.log(2, obj)
    },
    async getData() {
      // 基于准备好的dom，初始化echarts实例
      console.log(this.$refs.main)
      const myChart = echarts.init(this.$refs.main)
      // 指定图表的配置项和数据
      const { data: res } = await this.$http.get('reports/type/1')
      if (res.meta.status !== 200) return this.$message.error('获取折线图失败')
      console.log(res.data)
      const obj = {}
      /* Object.assign(obj, this.options, res.data)
      console.log(obj) */
      _.merge(obj, res.data, this.options)
      console.log(obj)
      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(obj)
      // myChart.setOption(option)
    }
  }
}
</script>

<style lang="less" scoped></style>
